import {reqGetCategory1List,reqGetCategory2List,reqGetCategory3List,reqGetAttrInfoList} from '@/api/produce/attrs'
const state={
    category1List:[],
    category2List:[],
    category3List:[],
    attrInfoList:[]
}
const actions={
    // 获取一级分类商品数据
    async getCategory1List({commit}){
        const result = await reqGetCategory1List()
        if(result.code===200){
            commit('GETCATEGORY1LIST',result.data)
        }
    },
    // 获取二级分类商品数据
    async getCategory2List({commit},params){
        const result = await reqGetCategory2List(params)
        if(result.code === 200) {
            commit('GETCATEGORY2LIST',result.data)
        }
    },
    // 获取三级分类商品数据
    async getCategory3List({commit},params){
        const result = await reqGetCategory3List(params)
        if(result.code === 200) {
            commit('GETCATEGORY3LIST',result.data)
        }
    },
    // 根据选中的一级、二级、三级分类获取选中商品的属性数据
    async getAttrInfoList({commit},params){
        const result = await reqGetAttrInfoList(params)
        if(result.code === 200){
            commit('GETATTRINFOLIST',result.data)
            return 'ok'
        }else return Promise.reject(new Error('获取属性信息失败'))
    }
}
const mutations={
    GETCATEGORY1LIST(state,category1List){
        state.category1List = category1List
    },
    GETCATEGORY2LIST(state,category2List){
        state.category2List = category2List
    },
    GETCATEGORY3LIST(state,category3List){
        state.category3List = category3List
    },
    GETATTRINFOLIST(state,attrInfoList){
        state.attrInfoList = attrInfoList
    }
}


export default {namespaced: true,state,actions,mutations}